﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyTemplate
{
    public partial class LoginAjax : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserName"] == null)
            {
                Panel1.Visible = true;
                btnLogout.Visible = false;
            }
            else
            {
                lblResult.Text = "환영합니다.";
                Panel1.Visible = false;
                btnLogout.Visible = true;
            }
        }
        protected void btnLogout_Click(object sender, EventArgs e)
        {
            Panel1.Visible = true;
            btnLogout.Visible = false;
            if (Request.Cookies["UserName"] != null)
            {
                HttpCookie myCookie = new HttpCookie("UserName");
                myCookie.Expires = DateTime.Now.AddDays(-1d);
                Response.Cookies.Add(myCookie);
                //Response.Cookies.Remove("UserName");
            }
            Page.Response.Redirect(Page.Request.Url.ToString(), true);
        }
    }
}